﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Fishpark.PdfWriter.Linearisation
{
    /// <summary>
    /// The CrossReferenceTable class represents a single cross-reference table in a PDF document.
    /// </summary>
    class CrossReferenceTable
    {
        // Private fields
        // ==============
        #region Private fields
        private int _start;
        private int _length;
        private List<CrossReferenceEntry> _entries;
        #endregion



        // Public properties
        // =================
        #region Public properties
        /// <summary>
        /// Retrieves a list of the entries in this table.
        /// </summary>
        public IEnumerable<CrossReferenceEntry> Entries
        {
            get
            {
                foreach (CrossReferenceEntry entry in _entries) yield return entry;
            }
        }

        /// <summary>
        /// Retrieves the number of objects in this table.
        /// </summary>
        public int Length
        {
            get { return _length; }
        }

        /// <summary>
        /// Retrieves the starting object in this table.
        /// </summary>
        public int Start
        {
            get { return _start; }
        }
        #endregion



        // Public methods
        // ==============
        #region Public methods
        /// <summary>
        /// Adds a new object reference to the cross-reference table.
        /// </summary>
        /// <param name="objRef">The object reference</param>
        /// <param name="location">The location of the object within the source file</param>
        public void Add(PdfObjectReference objRef, long location)
        {
            _entries.Add(new CrossReferenceEntry(objRef, location));
        }
        #endregion



        // Public constructor
        // ==================
        #region Public constructor
        /// <summary>
        /// Constructs a new CrossReferenceTable instance.
        /// </summary>
        /// <param name="start">The start object</param>
        /// <param name="length">The number of objects in this table</param>
        public CrossReferenceTable(int start, int length)
        {
            _start = start;
            _length = length;
            _entries = new List<CrossReferenceEntry>();
        }
        #endregion

    } // CrossReferenceTable class
}
